package com.hw.protocol.tool.decode.hw;

import com.hw.protocol.tool.model.entity.hw.AbsFlowMeter;
import com.hw.protocol.tool.model.entity.hw.Dtu37;

/**
 * @author : lihy
 * @date : 2023/3/23 14:14
 * description: 流量计(37768/37868)实时数据解码器
 */
public class Dtu37Decode extends FlowMeterDecodeTemplate {

    private Dtu37 fm;

    Dtu37Decode(AbsFlowMeter fm, byte[] data) {
        super(fm, data);
        this.fm = (Dtu37) fm;
    }

    @Override
    void setVolume() {
        String volumeStr = dataBuf.readUnsignedIntLE() + dataBuf.readFloatLE() + "";
        fm.setVolume(Double.parseDouble(volumeStr));
    }

    @Override
    void setRealVolume() {
        String volumeStr = dataBuf.readUnsignedIntLE() + dataBuf.readFloatLE() + "";
        fm.setRealVolume(Double.parseDouble(volumeStr));
    }

    @Override
    void setReverseVolume() {
        String volumeStr = dataBuf.readUnsignedIntLE() + dataBuf.readFloatLE() + "";
        fm.setReverseVolume(Double.parseDouble(volumeStr));
    }

    @Override
    boolean dtu37() {
        return true;
    }
}
